﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Aplicacion_Vista_MaterialesEnBodega : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        String nomRol = (String)Session["nombreRol"];
        String nomU = (String)Session["nombreUsuario"];

        if (nomRol == null || nomRol.Length <= 0 || nomU == null || nomU.Length <= 0)
        {
            Response.Redirect("Inicio.aspx");
        }

        String idBodega = Request.QueryString["i"];
        ControladorMaterialesEnBodega control = new ControladorMaterialesEnBodega();
        control.cargarMateriales(GridView1, idBodega);
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session["nombreRol"] = null;
        Session["nombreUsuario"] = null;
        Session["idRol"] = null;
        Session.Abandon();
        Response.Redirect("Inicio.aspx", true);
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "traspaso")
        {
            DataTable dt = (DataTable)GridView1.DataSource;
            int page = GridView1.PageIndex;
            int numPages = GridView1.PageSize;
            int preindex = Int16.Parse(e.CommandArgument.ToString());
            int index = preindex + page * numPages;

            String idBodega = Request.QueryString["i"];
            String idMaterial = (String)(dt.Rows[index].ItemArray[5]);
            String cantMaterial = (String)(dt.Rows[index].ItemArray[4]);
            String nombreBodega = Request.QueryString["n"];
            String deptoBodega = Request.QueryString["d"];
            String nomMaterial = (String)(dt.Rows[index].ItemArray[1]);
            String skuMaterial = (String)(dt.Rows[index].ItemArray[0]);
            Response.Redirect("TraspasoMaterial.aspx?ib=" + idBodega + "&im=" + idMaterial + "&cm=" + cantMaterial + "&nb="+nombreBodega+"&db="+deptoBodega+"&nm="+nomMaterial+"&sku="+skuMaterial+"");

        }
    }
}